package com.ruiyian.bridge.project.controller;

import com.ruiyian.bridge.project.domain.DeviceInfo;
import com.ruiyian.bridge.project.service.DeviceInfoService;
import com.ruiyian.common.core.controller.BaseController;
import com.ruiyian.common.core.domain.AjaxResult;
import com.ruiyian.common.core.page.TableDataInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
* @Description: 设备信息
* @Author: jeecg-boot
* @Date:   2020-08-25
* @Version: V1.0
*/
@RestController
@RequestMapping("/bm/device")
@SuppressWarnings("deprecation")
@Slf4j
public class DeviceController extends BaseController {
   @Autowired
   private DeviceInfoService deviceService;

   /**
    * 分页列表查询
    *
    * @param device
    * @return
    */
   @GetMapping(value = "/list")
   public TableDataInfo queryPageList(DeviceInfo device) {
       startPage();
       List<DeviceInfo> list = deviceService.querySeachList(device);
       return getDataTable(list);
   }


   @GetMapping(value = "/listAll")
   public AjaxResult querySeachList(DeviceInfo device ) {
       List<DeviceInfo> pageList = deviceService.querySeachList(device);
       return AjaxResult.success(pageList);
   }

   /**
    *   添加
    *
    * @param device
    * @return
    */
   @PostMapping(value = "/add")
   public AjaxResult add(@RequestBody DeviceInfo device) {
       deviceService.save(device);
       return AjaxResult.success("添加成功！");
   }

   /**
    *  编辑
    *
    * @param device
    * @return
    */
   @PutMapping(value = "/edit")
   public AjaxResult edit(@RequestBody DeviceInfo device) {
       deviceService.updateById(device);
       return AjaxResult.success("编辑成功!");
   }

   /**
    *   通过id删除
    *
    * @param id
    * @return
    */
   @DeleteMapping(value = "/delete")
   public AjaxResult delete(@RequestParam(name="id",required=true) String id) {
       deviceService.removeById(id);
       return AjaxResult.success("删除成功!");
   }


   /**
    * 通过id查询
    *
    * @param id
    * @return
    */
   @GetMapping(value = "/queryById")
   public AjaxResult queryById(@RequestParam(name="id",required=true) String id) {
       DeviceInfo device = deviceService.getById(id);
       if(device==null) {
           return AjaxResult.error("未找到对应数据");
       }
       return AjaxResult.success(device);
   }

   @GetMapping(value = "/query/device/num")
   public AjaxResult queryDeviceNum(@RequestParam(name="bridgeId",required=true) Integer bridgeId) {
       return AjaxResult.success(deviceService.queryDeviceNum(bridgeId));
   }

}
